part of '../repository.dart';

class _LearningStageDtoFactory {
  const _LearningStageDtoFactory._internal();

  static const _instance = _LearningStageDtoFactory._internal();

  factory _LearningStageDtoFactory() {
    return _instance;
  }

  _LearningStageDto fromJson(Map<String, dynamic> json) {
    final type = json[_kLearningStageTypeKey] as String;

    switch (type) {
      case _kRepeatableLearningStageTypeValue:
        return _RepeatableLearningStageDto.fromJson(json);
      case _kSuspendedLearningStageTypeValue:
        return _SuspendedLearningStageDto.fromJson(json);
      default:
        throw UnimplementedError();
    }
  }

  _LearningStageDto fromEntity(LearningStage learningStage) {
    switch (learningStage) {
      case RepeatableLearningStage():
        return _RepeatableLearningStageDto.fromEntity(learningStage);
      case SuspendedLearningStage():
        return _SuspendedLearningStageDto.fromEntity(learningStage);
    }
  }
}
